<template>
	<!-- 美发详情 -->
	<view>
		<swiper class="screen-swiper" :class="'square-dot'" :indicator-dots="true" :circular="true" :autoplay="true"
			interval="5000" duration="500">
			<swiper-item v-for="(item,index) in food.main_images" :key="index">
				<image :src="url+item" mode="aspectFill"></image>
				<!-- <video src="/static/zwss.png" v-else></video> -->
			</swiper-item>
		</swiper>
		<view class="head bg-white">
			<view class="title">{{food.name}}</view>
			<view class="money flex-cb">
				<view class="left">
					<text>原价：</text>
					<text class="icon">￥</text>
					<text class="num">{{property.price}}</text>
				</view>
				<view class="right flex align-end">
					<image src="/static/vip.png" class="icon_div" mode=""></image>
					<text class="jifen">会员价：</text>
					<text class="icon">￥</text>
					<text class="num" style="margin-right: 25rpx;">{{property.vip_price}}</text>
				</view>
			</view>
			<view class="money money2  flex-cb">
				<view class="left" style="margin-top: 20rpx;">
					<text>库存 {{property.stock||0}}</text>
				</view>
				<view class="right flex align-end" v-if="property.point_deduct_amount != 0">
					<image src="/static/jf.png" class="icon_div" mode=""></image>
					<text class="jifen">积分最多抵扣：</text>
					<text class="icon">￥</text>
					<text class="num">{{property.point_deduct_max_amount||0}}</text>
				</view>
			</view>
		</view>
		<!-- 评价 -->
		<view class="pinjia bg-white" v-if="list.length">
			<view class="title flex-cb">
				<text class="text">图文评价（{{list.length}}）</text>
				<navigator :url="'/pageB/more?id='+food.id">
					<view class="more flex-cb">
						<text>查看更多</text>
						<text class="cuIcon-right"></text>
					</view>
				</navigator>
			</view>
			<scroll-view class="pinjia_list" scroll-y="true">
				<view v-for="(item,index) in list" :key="index" class="item">
					<view class="solid"></view>
					<view class="user_img flex-cb">
						<image :src="item.user.avatar?url+item.user.avatar:'/static/logo.png'" mode=""></image>
						<view class="user_name flex-cb">
							<view>
								<view class="name">{{item.user.nickname?item.user.nickname:'微信用户'}}</view>
								<text class="time">{{item.created_at}}</text>
							</view>
							<view>
								<text v-for="(i,t) in 5" :key="t" class="cuIcon-favorfill"
									:class="{icon:t < item.star}"></text>
							</view>
						</view>
					</view>
					<view class="pinyu">{{item.content}}</view>
					<view class="flex pinyu_img">
						<view class="" v-for="(i,j) in item.files" :key="j">
							<image :src="url+i" mode=""></image>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 商品详情 -->
		<view class="details bg-white">
			<view class="sp_details flex-c">
				<view class="solid"></view>
				<text>商品详情</text>
				<view class="solid"></view>
			</view>
			<image :src="url+ food.detail" mode="widthFix" v-if="isfile"></image>
			<video :src="url+ food.detail" v-else></video>
		</view>
		<!--  -->
		<view class="foot bg-white flex-cb">
			<view class="left flex-cb">
				<!-- 			<view class="icon_div" @click="phone">
					<image src="/static/dh2.png" mode=""></image>
					<view class="">拨打电话</view>
				</view> -->
				<view class="icon_div " @click="navigate(1)">
					<text class="cuIcon-shop"></text>
					<view class="">店铺</view>
				</view>
			</view>
			<view class="right flex-cb">
				<!-- <view v-if="main_id == 2" @click="isdisplay = 1" class="button button2">加入购物车</view> -->
				<view class="button button2" @click="navigate">立即预约</view>
			</view>
		</view>
		<!-- 规格选择弹窗 -->
		<view class="tx" v-show="isdisplay == 1" @click="isdisplay = 0"></view>
		<view class="time bg-white" v-show="isdisplay == 1">
			<view class="type" v-for="(i,k) in allProperty" :key="k">
				<text>{{i.spec_name}}</text>
				<view class="type_list flex flex-wrap">
					<!-- :class="{item:key == istype[key]}" -->
					<view v-for="(item,key) in i.item_list" :key="key" class="flex-c" @click="istypes(k,key)"
						:class="istype[k] == key?'item':'' ">
						{{item.item_name}}
					</view>
				</view>
			</view>
			<view class="type" v-for="(i,k) in attribute" :key="k">
				<text>{{i.attribute_name}}</text>
				<view class="type_list flex flex-wrap">
					<view v-for="(item,key) in i.name" :key="key" class="flex-c" @click="istypes2(k,key)"
						:class="istype2[k] == key?'item':'' ">
						{{item}}
					</view>
				</view>
			</view>
			<view class="num flex-cb">
				<text>购买数量</text>
				<view class="num_div flex-cb">
					<view @click.stop="__num">-</view>
					<view class="addnum">{{num}}</view>
					<view @click.stop="addNum">+</view>
				</view>
			</view>
			<view class="button flex-c button2 " @click="handlecart">加入购物车</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				jj: 0,
				arr: [],
				url: '',
				isdisplay: 0,
				ispay: 0,
				isshow: 0,
				isshow1: 0,
				mch_id: '',
				main_id: '',
				isindex: 0,
				num: 1,
				food: '',
				isfile: 1,
				shop: {},
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				property: '',
				allProperty: '', //商品全部属性
				attribute: '',
				num: 1,
				// 规格类型选择
				istype: [0],
				// 属性选择
				istype2: [],
			};
		},
		onLoad(e) {
			this.url = this.$base
			this.mch_id = e.mch_id
			this.isindex = e.index
			this.shop = {
				id: e.id
			}
			console.log(e, '传过来的参数');
			console.log('店铺类型', this.main_id);
			this.$api.goods_list_details({}, e.id, 0).then(res => {
				console.log(res);
				this.food = res.data
				this.main_id = this.food.category_id
				console.log('店铺类型', this.main_id);
				// this.property = res.data.sku.spec_list[0].item_list[0]
				this.property = res.data.service
				this.allProperty = this.food.service
				this.attribute = this.food.service.items
				console.log('商品属性', this.attribute);
				let len = this.allProperty.length
				for (let i = 0; i < len+1; i++) {
					this.istype2[i] = 0
				}
				// console.log('商品详情', this.property);
				// console.log('商品全部详情', this.food.sku.spec_list);
				// this.getMerchants(this.food.mch_id)
				// this.getlist(this.food.id)
				// this.arr = JSON.parse(JSON.stringify(this.food.sku.attribute_list));
				// for (let i = 0; i < this.arr.length; i++) {
				// 	this.arr[i].name.splice(1,3)
				// }
				// console.log(this.arr);
				let t = null
				t = res.data.detail.split('.')[1]
				if (this.isAssetTypeAnImage(t)) {
					this.isfile = 1
				} else {
					this.isfile = 0
				}
			})
		},
		methods: {
			istypes(k, key) {
				this.istype[k] = key
				console.log(this.istype);
				this.$forceUpdate()
			},
			istypes2(k, key) {
				this.istype2[k] = key
				console.log(this.istype);
				this.$forceUpdate()
			},
			phone() {
				uni.makePhoneCall({
					phoneNumber: this.shop.contact_phone,

				})
			},
			__num() {
				if (this.num != 1) {
					this.num--
				} else {
					uni.showToast({
						icon: "none",
						title: '不能再少了~'
					})
				}
			},
			addNum() {
				// console.log(this.istype);
				// 检查库存
				if (this.food.sku.service.stock == this.num) {
					return
				} else {
					this.num++
				}
			},
			handlecart() {
				let newarr = []
				let attribute_name = []
				let len = this.allProperty.length
				for (let i = 0; i < len+1; i++) {
					attribute_name.push(this.attribute[i].name[this.istype2[i]])
				}
				let shop = {
					spec_name: this.attribute[0].name,
					spec_item_name: this.attribute[0].name,
					attribute_name: attribute_name,
					number: this.num,
				}
				console.log(shop);
				for (let i = 0; i < this.arr.length; i++) {
					newarr[i] = this.arr[i].name
				}
				// if(newarr.length !== 0){
					this.$api.ADD_cart(shop,this.food.id,1).then(res=>{
						console.log(res);
						if(res.code ==200001){
							uni.navigateBack(-1)
						}
						this.isdisplay = 0
					})
				// }

			},
			// handleArr(t,j){//选择属性
			// 	this.arr[j].name = t
			// },
			//判断是否是图片
			isAssetTypeAnImage(t) {
				return ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(t.toLowerCase()) !== -1;
			},
			getlist(id) {
				this.$api.comments_list({
					page: this.page,
					limit: this.limit
				}, id, 1).then(res => {
					this.last_page = res.last_page
					console.log(res);
					this.list = [...this.list, ...res.list]
				})
			},
			navigate(status) {
				// if(status == 1){
				// 	uni.navigateTo({
				// 		url: '../shop?e=' + JSON.stringify(e)
				// 	})
				// 	return
				// }
				uni.navigateTo({
					url: '/pageB/meifa_details/meifa_yuyue?shop=' + JSON.stringify(this.shop) + '&food=' + JSON
						.stringify(this.food)
				})
			},
			// got(){
			// 	let newarr = {
			// 		sx:[],
			// 		spec:'',
			// 		price:'',
			// 		id:'',
			// 		vip_price:'',
			// 		point:'',
			// 		point_100:'',
			// 		number:1,
			// 	}
			// 	for (let i = 0; i < this.arr.length; i++) {//商品属性
			// 		newarr.sx[i] =  this.arr[i].name
			// 	}
			// 	newarr.id = this.food.id
			// 	newarr.main_images =this.url+ this.food.main_images[0]
			// 	newarr.name = this.food.name
			// 	newarr.spec = this.food.sku.spec_list[0].item_list[this.jj].item_name//规格项
			// 	newarr.specname = this.food.sku.spec_list[0].spec_name//规格名称
			// 	newarr.price = this.food.sku.spec_list[0].item_list[this.jj].price//价格
			// 	newarr.vip_price = this.food.sku.spec_list[0].item_list[this.jj].vip_price//会员价
			// 	newarr.point_price = this.food.sku.spec_list[0].item_list[0].point_deduct_max_amount//积分价
			// 	newarr.point_100 = this.food.sku.spec_list[0].item_list[0]['100_point_deduct_amount']//100积分抵扣
			// 	newarr.number = this.num//数量

			// 	uni.navigateTo({
			// 		url:'./Submit_order?data=' + JSON.stringify(newarr) + '&shop='+JSON.stringify(this.shop)
			// 	})
			// 	this.isdisplay = 0
			// },
			getMerchants(id) {
				this.$api.get_merchants({}, id, 1).then(res => {
					this.shop = res.data
				})
			},
		}
	}
</script>

<style lang="scss">
	.tx {
		position: fixed;
		left: 0rpx;
		top: 0rpx;
		width: 100vw;
		height: 100vh;
		z-index: 97;
		background-color: #24211f;
		opacity: 0.3;
	}

	.time {
		width: 750rpx;
		border-radius: 10rpx;
		margin: 0rpx 0rpx;
		padding-bottom: 10rpx;
		position: fixed;
		bottom: 0rpx;
		left: 0rpx;
		z-index: 99;

		.button {
			margin: 10rpx auto;
			width: 480rpx;
			height: 81rpx;
			text-align: center;
			color: #fff;
			line-height: 81rpx;
			border-radius: 41rpx;
		}

		.button2 {
			background: #1CD699;
		}
	}

	.num {
		padding: 31rpx 30rpx 0rpx 28rpx;

		text {
			font-size: 30rpx;
			color: #2F2F2F;
			font-weight: bold;
		}

		.time_pic {
			text {
				color: #1CD699;
			}

			.cuIcon-right {
				font-size: 25rpx;

			}
		}

		.num_div {
			view {
				width: 60rpx;
				height: 60rpx;
				background: #F2F2F2;
				text-align: center;
				line-height: 60rpx;
				border-radius: 10rpx;
			}

			.addnum {
				width: 100rpx;
				margin: 0 20rpx;
			}
		}
	}

	.type {
		width: 750rpx;
		height: auto;
		border-radius: 10rpx;
		margin: 0rpx 0rpx;
		padding: 20rpx 24rpx 30rpx 24rpx;

		text {
			font-size: 30rpx;
			font-weight: bold;
			color: #2F2F2F;
		}

		.type_list {
			margin-top: 41rpx;

			view {
				width: 121rpx;
				height: 60rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				font-size: 28rpx;
				color: #999999;
				margin-right: 16rpx;
			}

			.item {
				color: #fff;
				background: #1CD699;
			}
		}
	}

	.head {
		width: 100%;
		height: 297rpx;
		padding: 20rpx 29rpx;

		.title {
			width: 680rpx;
			height: 108rpx;
			font-size: 34rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #000000;
			line-height: 60rpx;
		}

		.money {
			margin-top: 8rpx;
			margin-bottom: 28rpx;

			.icon {
				font-size: 22rpx;
				color: #333;
			}

			.num {
				font-size: 42rpx;
				color: #333;
				// height: 59rpx;
			}

			.left {
				text {
					font-size: 24rpx;
					color: #999999;
				}

			}

			.right {
				min-width: 80rpx;

				.icon,
				.num {
					color: #FF2E2E;
				}

				.jifen {
					white-space: nowrap;
					font-size: 24rpx;
				}

				.icon_div {
					margin-right: 12rpx;
					width: 34rpx;
					height: 40rpx;
				}
			}
		}

		.money2 {
			.right {

				.icon,
				.num {
					color: #FF6F10;
				}
			}
		}
	}

	.pinjia {
		height: 810rpx;
		margin: 10rpx auto;
		overflow: hidden;

		.title {
			padding: 28rpx 29rpx;

			.text {
				font-weight: bold;
				font-size: 30rpx;
				color: #666666;
			}

			.more {
				font-size: 28rpx;
				color: #1CD699;
			}
		}

		.solid {
			width: 720rpx;
			position: relative;
			left: -30rpx;
			top: -25rpx;
		}

		.pinjia_list {
			overflow: hidden;

			.item {
				padding: 27rpx 18rpx 28rpx 45rpx;

				.user_img {
					image {
						width: 60rpx;
						height: 60rpx;
						border-radius: 50%;
					}

					.user_name {
						padding-left: 19rpx;
						flex: 1;

						.name {
							font-size: 28rpx;
							color: #333;
						}

						.time {
							font-size: 20rpx;
							color: #999999;
						}

						.cuIcon-favorfill {
							color: #EBEBEB;
						}

						.icon {
							color: #FF6F10;
						}
					}
				}

				.pinyu {
					margin-top: 13rpx;
					margin-bottom: 25rpx;
					font-size: 28rpx;
					color: #333333;
				}

				.pinyu_img {
					image {
						width: 160rpx;
						height: 160rpx;
						margin-right: 20rpx;
						border-radius: 10rpx;
					}
				}
			}
		}
	}

	.details {
		width: 100%;
		height: auto;
		min-height: 750rpx;
		padding-bottom: 120rpx;

		.sp_details {
			height: 88rpx;

			text {
				font-size: 32rpx;
				color: #333333;
				margin: 0 26rpx;
			}

			.solid {
				width: 86rpx;
			}
		}

		image,
		video {
			width: 100%;
		}
	}

	.foot {
		width: 100%;
		height: 120rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		padding-left: 42rpx;
		padding-right: 26rpx;

		.left {
			font-size: 24rpx;

			.icon_div {
				width: 96rpx;
				text-align: center;
				margin-right: 28rpx;

				image {
					width: 44rpx;
					height: 45rpx;
				}
			}

			.cuIcon-service,
			.cuIcon-shop {
				font-size: 50rpx;
			}
		}

		.right {
			.button {
				width: 480rpx;
				height: 81rpx;
				text-align: center;
				color: #fff;
				line-height: 81rpx;
				border-radius: 41rpx;
			}

			.button2 {
				background: #1CD699;
			}
		}
	}
</style>
